//
//  FlyweightTicketFactory.swift
//  ArchitectGenerics
//
//  Created by 姚胜龙 on 2017/6/20.
//  Copyright © 2017年 姚胜龙. All rights reserved.
//

import UIKit

//对象池  就是缓存（缓存可以用 数组Array<T>() 字典[key:value] 集合Set<T>()）
class FlyweightTicketFactory: NSObject {
    static var ticketsDictionary = [String: FlyweightTicketProtocol]()
    //获取车票的信息
    class func ticket(from:String, to:String) -> FlyweightTicketProtocol {
        let key = from+"-"+to
        if ticketsDictionary[key] == nil {
            ticketsDictionary[key] = FlyweightTicket(from: from, to: to)
        }
        return ticketsDictionary[key]!
    }
}
